package com.coding.service.impl;

import com.coding.base.pojo.BaseModel;
import com.coding.dao.AgainDao;
import com.coding.dao.AgainmarkDao;
import com.coding.pojo.Again;
import com.coding.pojo.Againmark;
import com.coding.service.AgainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther wangchenghao
 * @date 2020/8/28
 **/
@Service
public class AgainImpl implements AgainService {
    @Autowired
    AgainDao againDao;
    @Autowired
    AgainmarkDao againmarkDao;

    @Override
    public void selectAll(BaseModel baseModel) throws Exception {
        List<Again> againList = againDao.selectAll();
        if (againList != null) {
            for (Again again : againList
            ) {
                List<Againmark> againmarkList = againmarkDao.selectByWayId(again.getAgain_way_id());
                if (againmarkList != null) {
                    again.setAgainmarkList(againmarkList);
                }
            }
            baseModel.setSucceed("成功获得诗人足迹", againList);
        } else {
            baseModel.setFailure("获得诗人足迹失败");
        }
    }

    @Override
    public void selectById(int again_id, BaseModel baseModel) throws Exception {
        Again again = againDao.selectByPrimaryKey(again_id);
        if (again != null) {
            List<Againmark> againmarkList = againmarkDao.selectByWayId(again.getAgain_way_id());
            if (againmarkList != null) {
                again.setAgainmarkList(againmarkList);
            }
            baseModel.setSucceed("成功获得诗人足迹", again);
        } else {
            baseModel.setFailure("获得诗人足迹失败");
        }
    }
}
